import fs from 'fs'
import { readdir, open, writeFile } from 'node:fs/promises';
import { utils, qrc, lrcx, lrc } from 'smart-lyric'
import path  from 'node:path'

const originPath = 'D:\\QQMusicCache\\QQMusicLyricNew\\'
const outPath = 'd:\\lyric\\'

try{
	const fileList = await readdir(originPath)
	for(const file of fileList)
	{
		const regex = /.*\.qrc/
		if(file.match(regex))
		{
			//console.log("匹配")
			const res = await decryptQrc(path.join(originPath,file))
			const outFile = path.join(outPath,file+'.txt')
			const fp = await open(outFile,"w")
			await writeFile(fp,res)
		}
		else
		{
			//console.log("不匹配")
		}
		
	}
}
catch(err){
	console.log(err)
}


async function decryptQrc(file){
	// 解码.qrc格式的歌词
	const qrcTextFromFile = qrc.decrypt(fs.readFileSync(file))
	//console.log(qrcTextFromFile)		//输出qrc歌词的XML文本
	return qrcTextFromFile
	// 歌词内容解析
	// const lyric = qrc.parse(qrcTextFromFile)
	// console.log(lyric)					//输出解析后的歌词信息
}
